require("Entity")

Link = class("Link", Entity)

---

function Link:initialize(name, container1, container2, numberOfEnablingSteps, type)
	
	if not type then
		type = "Link"
	end
		
	Entity.initialize(self, type, name)
	
	self:registerEntityType("Link")
	
	self.container1 			= container1
	self.container2 			= container2
	self.numberOfEnablingSteps	= numberOfEnablingSteps
	
	self:addProperty("EnablingSteps", 1, numberOfEnablingSteps)
end

---

function Link:getOtherSide(thisSideContainer)

	if thisSideContainer == self.container1 then
		return self.container2
	elseif thisSideContainer == self.container2 then
		return self.container1
	end
	
	error("Specified 'thisSideContainer' is not connected this door")
end

---

function Link:enable()

	self:collapseProperty("EnablingSteps", self.numberOfEnablingSteps)
end

---

function Link:increaseEnabling(increment)

	self:collapseProperty("EnablingSteps")
	
	local enablingStep = self:getCollapsedProperty("EnablingSteps")
	
	self:collapseProperty("EnablingSteps", enablingStep + increment)
end

---

function Link:disable()

	self:collapseProperty("EnablingSteps", 1)
end

---

function Link:isEnabled(notCollaspedIsEnabled)

	if 
		not self:isPropertyCollasped("EnablingSteps") 
	then	
		return notCollaspedIsEnabled
	else
		return self:getCollapsedProperty("EnablingSteps") >= self.numberOfEnablingSteps
	end
end

--

function Link:isDisabled(notCollaspedIsEnabled)

	return not self:isEnabled(notCollaspedIsEnabled)
end

---

function Link:hasUndeterminedSate()

	return not self:isPropertyCollasped("EnablingSteps")
end